// https://leetcode.cn/problems/count-and-say/description/

import "strconv"
func lze(s string) string {
	n := len(s)
	if n == 0 {
		return ""
	}
	if n == 1 {
		return "1" + s
	}
	ans := ""
	c := 1
	for i := 1; i < n; i++ {
		if s[i] == s[i - 1] {
			c++
		} else {
			num, _ := strconv.Itoa(c)
			ans += num + string(s[i - 1])
			c = 1
		}
	}
	num, _ := strconv.Itoa(c)
	ans += num + string(s[i - 1])
	return ans
}

func countAndSay(n int) string {
    rec := make([]string, n + 1)
	rec[1] = "1"
	for i := 2; i < n + 1; i++ {
		rec[i] = lze(rec[i-1])
	}
	return rec[n]
}